package com.sky.controller.user;


import com.sky.dto.OrdersPageQueryDTO;
import com.sky.dto.OrdersSubmitDTO;
import com.sky.entity.Orders;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.OrderService;
import com.sky.vo.OrderSubmitVO;
import com.sky.vo.OrderVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.annotation.Order;
import org.springframework.web.bind.annotation.*;

@RestController
@Api("订单相关接口")
@Slf4j
public class OrderController {

    @Autowired
    private OrderService orderService;

    @PostMapping("/user/order/submit")
    @ApiOperation("用户下单")
    public Result<OrderSubmitVO> subitOrder( @RequestBody OrdersSubmitDTO ordersSubmitDTO) {
        log.info("用户下单");
        OrderSubmitVO orderSubmitVO = orderService.submitOrder(ordersSubmitDTO);
        return Result.success(orderSubmitVO);
    }


    @GetMapping("/user/order/historyOrders")
    @ApiOperation("查询历史订单")
    public Result<PageResult> getHistoryOrders(int page ,int pageSize,Integer status) {
        log.info("查询历史订单");
        PageResult pageResult =  orderService.page(page,pageSize,status);
        return Result.success(pageResult);
    }


    @GetMapping("/user/order/orderDetail/{id}")
    @ApiOperation("查询订单详细")
    public Result<OrderVO>  getOrderById(@PathVariable Long id) {
        log.info("查询订单详细");

        OrderVO orderVO = orderService.getOrderDetail(id);
        return Result.success(orderVO);
    }


    @PostMapping("/user/order/repetition/{id}")
    @ApiOperation("再来一单")
    public Result repetition(@PathVariable Long id){
        log.info("再来一单");
        orderService.repetition(id);
        return Result.success();
    }
}
